<?php 
	include($_SERVER['DOCUMENT_ROOT']."/headerins.php");
	include($_SERVER['DOCUMENT_ROOT']."/headerFrame.php");


echo '
<div id="contextCaption">Изменение позиции заказа.</div>
<div id="insert_response"></div>
<hr>
<form action="javascript:Request('."'".'OrderLine'."'".', '."'".'update'."'".', '."'".''.$_GET['OrderLineID'].''."'".')" method="POST">
    <table border="0" id="contextGrid" cellspacing="0" width="100%">
';
		$OrderLineID = $_GET['OrderLineID'];
		$MaterialID = 0;
		$Qty = 0;
		$Price1 = 0;
		$Summ = 0;
		$Ball = 0;
		$Balls = 0;

		$result = mysql_query(
			'SELECT m.Code, m.Name, o.Qty, o.Price1, (o.Qty * o.Price1) Summ, o.Ball, (o.Qty * o.Ball) Balls 
				FROM orderline o
				left join material m on m.ID = o.materialID
				WHERE OrderLineID = '.$OrderLineID);
		if (!$result)
			die('Order/change/sql: ' . mysql_error(). $sql);

		while($row = mysql_fetch_array($result)){
				$Code = $row['Code'];
				$Name = $row['Name'];
				$Qty = $row['Qty'];
				$Price1 = $row['Price1'];
				$Summ = $row['Summ'];
				$Ball = $row['Ball'];
				$Balls = $row['Balls'];
		}

echo '
        <tr><th style="width: 40px;"><label for="MaterialID">#Продукта</label>
		
					<td><input list="Materials" id="MaterialID" value="'.$Code.'" onchange="getMaterialDetail()" style="width: 70%; float: left;">
					<datalist id="Materials">
';
								$result = mysql_query("
									SELECT 
										ID, Code, Name
									FROM material");
								
								$rows = array();
								while($row = mysql_fetch_array($result)){
									if($row['Code'] == $Code)
										echo '<option selected="selected" value="'.$row['Code'].'">'.$row['Code'].' - '.$row['Name'].'</option>';  
									else 
										echo '<option value="'.$row['Code'].'">'.$row['Code'].' - '.$row['Name'].'</option>';  
								}
echo '
					</datalist>	
	
		</td></th></tr>
		<tr><th style="width: 40px;"><label for="MatName">Название</label><td><input type="text" value="'.$Name.'"   id="MatName" disabled="disabled" style="width: 70%; float: left;"></td></th></tr>
		<tr><th style="width: 40px;"><label for="Qty">Количество</label><td><input type="text" value="'.$Qty.'"  class="integer" id="Qty"  onkeyup="calc()" style="float: left;"></td></th></tr>
		<tr><th style="width: 40px;"><label for="Price1">Цена</label><td><input type="text" value="'.$Price1.'"   id="Price1" disabled="disabled" style="float: left;"></td></th></tr>
		<tr><th style="width: 40px;"><label for="Summ">Сумма</label><td><input type="text" value="'.$Summ.'"   id="Summ" disabled="disabled" style="float: left;"></td></th></tr>
		<tr><th style="width: 40px;"><label for="Ball">Балл</label><td><input type="text" value="'.$Ball.'"   id="Ball" disabled="disabled" style="float: left;"></td></th></tr>
		<tr><th style="width: 40px;"><label for="Balls">Баллы</label><td><input type="text" value="'.$Balls.'"   id="Balls" disabled="disabled" style="float: left;"></td></th></tr>

    </table>
    <hr>
	<div id="orderline" height=100% style="margin: 0px; padding: 0px;"></div>
	
	<div id="result"><div>
	
	<input id="OrderID" type="hidden" value="'.$_GET['OrderID'].'" >
	<input id="button" type="Button"  value="Отмена" title="Отмена" onclick="getPage('."'".'/core/Order/OrderUpdate.php?id='.	$_GET['OrderID'].	''."'".')">            
	
	<input id="button" type="submit" value="Сохранить" title="Сохранить введенные данные">

<script type="text/javascript">

	$(".numeric").numeric();
	$(".integer").numeric(false, function() { 
		this.value = "0"; 
		this.focus(); 
	});

	function calc(){
		document.getElementById('."'".'Summ'."'".').value = Number(document.getElementById('."'".'Price1'."'".').value) * Number(document.getElementById('."'".'Qty'."'".').value);
		document.getElementById('."'".'Balls'."'".').value = Number(document.getElementById('."'".'Ball'."'".').value) * Number(document.getElementById('."'".'Qty'."'".').value);
	};

</script>


</form>

';
